package com.aizhixin.test.errolAlmost.service;

import java.util.Calendar;
import java.util.Date;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aizhixin.test.errolAlmost.dao.TimeDifferenceDAO;
import com.aizhixin.test.errolAlmost.dto.loanAndNowDTO;

@Service
@Transactional
public class timeDifferenService {
@Autowired
private TimeDifferenceDAO timeDifferenceDAO;
	/*
	 * 输入一个openid然后查找时间差
	 */
	public Long getTimeDifference(String openId) {
		loanAndNowDTO loanAndNowDto=new loanAndNowDTO();
		loanAndNowDto=timeDifferenceDAO.getTime(openId);
		Long a;
		a=getDays(loanAndNowDto.getNowTime(), loanAndNowDto.getUserfirstLoanTime());
		return a;
	
	}
	/**
	 * 计算两个日期之间相差的天数
	 *
	 */
	public static Long getDays(Date end,Date start){
		Calendar aCalendar = Calendar.getInstance();
		//要用这个方法
        Calendar bCalendar = Calendar.getInstance();
        aCalendar.setTime(end);//设置日期
        bCalendar.setTime(start);
        long l1 = aCalendar.getTimeInMillis();
        long l2 =bCalendar.getTimeInMillis();// 转换为相对时间
        return (l1 - l2) / (24*60*60*1000);//进率
	}

}
